package com.hao.cloudadmin.modules.monitor.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author haozw
 * @date 2019-12-26
 */
@Slf4j
@Component
public class RedisInitialization implements ApplicationRunner {

    private final RedisTemplate redisTemplate;

    public RedisInitialization(RedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }


    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("-----------------项目清理redis缓存开始------------------");
        Set<String> keys = redisTemplate.keys("*");
        redisTemplate.delete(keys.stream().collect(Collectors.toList()));
        log.info("-----------------项目清理redis缓存结束------------------");
    }
}
